package com.eascs.ticket.ticket.format;

import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import java.util.Date;

import com.eascs.common.util.DateUtils;

public class DueDateViewFormat extends Format {

	private static final long serialVersionUID = 8278008625176875753L;

	@Override
	public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
		Date dueDate = (Date) obj;
		if (null == dueDate)
			return toAppendTo;
		long afterOneDate = dueDate.getTime() + 1000 * 3600 * 24;
		long beforeOneDate = dueDate.getTime();
		long now = System.currentTimeMillis();
		String style = "";
		if (dueDate.getTime() == 0) {
			toAppendTo.append("完成");
			return toAppendTo;
		} else if (now > afterOneDate) {
			style = " background-color: red; color: white;";
		} else if (now < afterOneDate & now >= beforeOneDate) {
			style = " background-color:yellow; color:red;";
		}
		toAppendTo.append("<span style=\"").append(style).append("\">").append(DateUtils.formateStandDate(dueDate)).append("</span>");
		return toAppendTo;
	}

	@Override
	public Object parseObject(String source, ParsePosition pos) {
		return null;
	}

}
